package com.flute.haflute.agent.job;

import java.util.List;

import com.flute.haflute.agent.topo.Node;

/**
 * 一项Job执行所获得的资源上下文：<br>
 * Job Id, 控制节点Master, Slaves等
 * 
 */
public class JobContext {

	private String jobId;
	private int numOfJob;
	private Node jobMaster;
	private List<Node> jobSlaves;

	public JobContext() {
		numOfJob = 0;
	}

	/** @return 工作控制节点 */
	public Node getJobMaster() {
		return jobMaster;
	}

	/** @param 设置工作控制节点 */
	public void setJobMaster(Node jobMaster) {
		this.jobMaster = jobMaster;
	}

	/** @return 执行任务的节点 */
	public List<Node> getJobSlaves() {
		return jobSlaves;
	}

	/**
	 * @param 设置工作的任务执行节点
	 *            ，即从节点
	 */
	public void setJobSlaves(List<Node> jobSlaves) {
		this.jobSlaves = jobSlaves;
	}

	public String getJobId() {
		return jobId;
	}

	public void setJobId(String jobId) {
		this.jobId = jobId;
	}

	public synchronized int getNumOfJob() {
		return numOfJob;
	}

	public synchronized void incJobCount() {
		this.numOfJob++;
	}

	public synchronized void decJobCount() {
		this.numOfJob--;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "JobId:" + jobId + "\tMaster:" + jobMaster + "\nSlaves:"
				+ jobSlaves + "\ntotal Jobs" + numOfJob;
	}

}
